/**
 * time: 2025-09-16
 * author: XJ
 * description: 产品基本信息页面
 */

import { CheckCircleOutlined, CloseCircleOutlined, InboxOutlined, SyncOutlined, UploadOutlined } from '@ant-design/icons';
import { useModel } from '@umijs/max';
import { Button, Cascader, Checkbox, DatePicker, Divider, Form, Input, InputNumber, message, Modal, Popconfirm, Row, Select, Space, Steps, TreeSelect, Upload } from 'antd';
import { Col } from 'antd/lib';
import TextArea from 'antd/es/input/TextArea';
import condition from '@/components/staticFile/treeSelect.json';
import { useEffect, useState, useRef } from 'react';
import { page } from '@/services/apis/serviceProviderRegister';
const COMMON_FIELD_STYLE = { width: '100%', height: 40, borderRadius: 4 };
import dayjs from 'dayjs';
import { govermentAuditProduct, updateProduct } from '@/services/apis/serviceProviderRegister';
import { filePreview, govermentAuditProgram, updateProgram, uploadFile } from '@/services/apis/companyRegister';
const FORM_LAYOUT = {
    labelCol: { span: 6 }, // 调整标签宽度，避免长标签换行
    wrapperCol: { span: 18 },
    layout: 'horizontal' as const,

    size: 'middle' as const, // 统一表单控件尺寸
};
const RecordAllInfosPage: React.FC<{ searchCallFun: any }> = (props) => {
    const {
        modalProps,
        setModalProps,
    } = useModel("RecordManager.modal")
    const [senceList, setSenceList] = useState<any[]>([]);
    const { initialState, setInitialState } = useModel('@@initialState');
    const [productNameList, setProductNameList] = useState<any[]>([])
    const [connectServiceList, setConnectServiceList] = useState<any[]>([])
    const [xydmList, setXydmList] = useState<any[]>([])
    const [hetongList, setHetongList] = useState<{ [key: string]: [] }>({})
    const connectService = useRef<any>({})
    const [form] = Form.useForm()
    const handleSubmit = () => {
        form.validateFields().then(values => {
            updateProgram({ ...values, id: modalProps.record.id, demandId: modalProps.record.demandId, projectId: modalProps.record.projectId }).then(res => {
                const { code } = res;
                if (code == "0") {
                    //message.success("更新产品信息成功")
                    setModalProps(prev => ({ ...prev, visible: false }))
                }
            })
        })
    };

    useEffect(() => {
        if (!modalProps.visible) return;
        page({
            current: "1", size: "10000",
            // status:"approved"
        }).then(res => {
            const { code, data } = res;
            if (code == "0") {
                const productNameList: any[] = [];
                const connectServiceList: any[] = [];
                const xydmList: any[] = [];
                data.records.forEach((item: any) => {
                    const product = {
                        value: item.productName,
                        label: item.productName
                    }
                    productNameList.push(product)
                    const service = {
                        value: item.supplierName,
                        label: item.supplierName
                    }
                    connectServiceList.push(service)
                    const xydm = {
                        value: item.xydm,
                        label: item.xydm
                    }
                    xydmList.push(xydm)
                    connectService.current[item.productName] = { supplierName: item.supplierName, xydm: item.xydm }
                })

                setProductNameList(productNameList);
                setConnectServiceList(connectServiceList)
                setXydmList(xydmList)
            }
        })

    }, [])
    const handleAutoUpload = async (file: any, formPath: any) => {

        try {
            const response = await uploadFile(file)
            if (response.code == "0") {
                setHetongList(prev => ({ ...prev, [formPath.join("_")]: [{ name: response.data.filename, uid: Math.random().toString() }] }))
                form.setFieldValue(formPath, [response.data])

            }
        } catch (error) {
        }
    };
    const convertNode = (node: any) => ({
        title: node.title,
        value: node.value,
        disabled: node.children && node.children.length > 0,
        children: node.children?.map(convertNode),
    });
    const buildFullPathMap = (
        nodes: any[],
        parentPath: string[] = [],
        map: Record<string, string[]> = {},
    ) => {
        nodes.forEach((node) => {
            const currentPath = [...parentPath, node.title];
            map[node.value] = currentPath;
            if (node.children && node.children.length) {
                buildFullPathMap(node.children, currentPath, map);
            }
        });
        return map;
    };

    const fullPathMap = buildFullPathMap(condition);
    useEffect(() => {
        form.setFieldsValue({ ...modalProps.record, companyChangeTime: dayjs(modalProps.record.companyChangeTime) })
        const hetongL: { [key: string]: any } = {}
        modalProps.record.digitalContentList?.forEach((item: any, index: any) => {
            const key = ["digitalContentList", index, 'changeContract'].join("_")
            hetongL[key] = item.changeContract?.map((fileItem: any) =>
                ({ ...fileItem, name: fileItem.filename, uid: Math.random().toString() }))
        })
        setHetongList(hetongL)
    }, [modalProps.record])
    const onCancel = () => {
        setModalProps(prev => ({ ...prev, visible: false }))
    }
    const onFinishFailed = (values: any) => { };

    async function handleReviewSubmit(arg0: string) {
        await form.validateFields()
        govermentAuditProgram({
            auditStatus: arg0,
            auditRemark: form.getFieldValue("auditRemark"),
            companyId: modalProps.record.companyId,
            auditUserId: initialState?.currentUser?.data.id,
            auditId: modalProps.record.auditId,
            userType: initialState?.currentUser?.data.userType,
            // auditDepartment:initialState?.currentUser?.data.departmentName
        }).then(res => {
            const { code } = res;
            if (code == "0") {
                //message.success("操作成功")
                props.searchCallFun();
            }
            setModalProps(prev => ({ ...prev, visible: false }))
        })

    }



    return (
        <Modal
            title={modalProps.title}
            open={modalProps.visible}
            onCancel={onCancel}
            footer={modalProps.title == "项目备案审核" ? null : [
                <Button key="back" onClick={onCancel}>
                    取消
                </Button>,
                <Button key="submit" type="primary"
                    onClick={handleSubmit}
                >
                    提交
                </Button>,
            ]}
            width={900}
            destroyOnClose
            maskClosable={false}
        >
            <Form
                {...FORM_LAYOUT}
                form={form}
            // name="basic"
            // labelCol={{ span: 8 }}
            // wrapperCol={{ span: 16 }}
            // style={{ maxWidth: '100%', paddingLeft: '20%', paddingRight: '20%' }}
            // initialValues={{ remember: true }}
            // onFinish={onFinish}
            // onFinishFailed={onFinishFailed}
            // autoComplete="off"
            // layout="vertical"
            >
                <div style={{ padding: 20, backgroundColor: '#f8f9fa', boxSizing: 'border-box' }}>
                    <div
                        style={{
                            backgroundColor: '#fff',
                            padding: 20,
                            borderRadius: 8,
                            boxShadow: '0 1px 3px rgba(0,0,0,0.05)',
                        }}
                    >
                        <div
                            style={{
                                fontSize: 16,
                                fontWeight: 500,
                                color: '#1f2937',
                                marginBottom: 12,
                            }}
                        >
                            数字化改造需求
                        </div>
                        {condition.map((item, index) => {
                            const nameLabel = `${item.title.includes(".") ? item.title.split(".")[1] : item.title}`
                            if (!(nameLabel in modalProps.record) && modalProps.title == "项目备案审核") {
                                return undefined;
                            }
                            return (
                                <>
                                    <div
                                        style={{
                                            fontSize: 16,
                                            fontWeight: 500,
                                            color: '#1f2937',
                                            marginBottom: 12,
                                            textIndent: 25
                                        }}
                                    >
                                        {nameLabel}面临需求
                                    </div>
                                    <Form.List name={nameLabel}>
                                        {(fields, { add, remove }) => (
                                            <>
                                                {fields.map(({ key, name, ...restField }) => (
                                                    <div
                                                        key={key}
                                                        style={{
                                                            marginBottom: 24,
                                                            borderBottom: '1px solid #e8e8e8',
                                                            paddingBottom: 16,
                                                        }}
                                                    >
                                                        <Row justify="space-between" align="middle">
                                                            <Col>
                                                                <div
                                                                    style={{
                                                                        fontSize: 16,
                                                                        fontWeight: 500,
                                                                        color: '#1f2937',
                                                                        marginBottom: 12,
                                                                    }}
                                                                >
                                                                    场景 {name + 1}
                                                                </div>
                                                            </Col>
                                                            <Col>
                                                                {
                                                                    modalProps.title != "项目备案审核" && (
                                                                        <Popconfirm title="是否删除" onConfirm={() => remove(name)}>
                                                                            <Button type="link" danger >
                                                                                删除
                                                                            </Button>
                                                                        </Popconfirm>
                                                                    )
                                                                }
                                                            </Col>
                                                        </Row>

                                                        {/* 场景选择 */}
                                                        <Form.Item
                                                            {...restField}
                                                            label="场景"
                                                            name={[name, 'scene']}
                                                            rules={[{ required: true, message: '请选择场景' }]}
                                                            style={{ marginBottom: 20 }}
                                                        >
                                                            <Cascader
                                                                className={modalProps.title == "项目备案审核" ? 'custom-readonly-select' : ''}
                                                                disabled={modalProps.title == "项目备案审核"}
                                                                allowClear
                                                                placeholder="请选择场景"
                                                                style={COMMON_FIELD_STYLE}
                                                                options={condition}
                                                                fieldNames={{ label: 'title' }}
                                                                showSearch
                                                            />
                                                        </Form.Item>

                                                        {/* 场景描述 */}
                                                        <Form.Item
                                                            {...restField}
                                                            label="场景描述"
                                                            name={[name, 'sceneDesc']}
                                                            rules={[{ required: true, message: '请输入场景描述' }]}
                                                            style={{ marginBottom: 20 }}
                                                        >
                                                            <TextArea
                                                                placeholder="请输入场景描述"
                                                                allowClear
                                                                readOnly={modalProps.title == "项目备案审核"}
                                                                showCount
                                                                maxLength={500}
                                                                style={{
                                                                    minHeight: 120,
                                                                    maxHeight: 200,
                                                                    resize: 'vertical',
                                                                    ...COMMON_FIELD_STYLE,
                                                                }}
                                                            />
                                                        </Form.Item>

                                                        {/* 问题及需求分析 */}
                                                        <Form.Item
                                                            {...restField}
                                                            label="问题及需求分析"
                                                            name={[name, 'problemAnalysis']}
                                                            rules={[{ required: true, message: '请输入问题及需求分析' }]}
                                                            style={{ marginBottom: 20 }}
                                                        >
                                                            <TextArea
                                                                placeholder="请输入问题及需求分析"
                                                                allowClear
                                                                showCount
                                                                readOnly={modalProps.title == "项目备案审核"}
                                                                maxLength={500}
                                                                style={{
                                                                    minHeight: 120,
                                                                    maxHeight: 200,
                                                                    resize: 'vertical',
                                                                    ...COMMON_FIELD_STYLE,
                                                                }}
                                                            />
                                                        </Form.Item>
                                                    </div>
                                                ))}
                                                {
                                                    modalProps.title != "项目备案审核" && (
                                                        <Form.Item wrapperCol={{ offset: 5, span: 19 }} style={{ marginTop: 40, textAlign: "center" }}>
                                                            <Button type="primary" onClick={() => add()} >
                                                                + 新增场景
                                                            </Button>
                                                        </Form.Item>
                                                    )
                                                }

                                            </>
                                        )}
                                    </Form.List>
                                </>
                            );
                        }).filter(Boolean)}
                        <div style={{ marginBottom: 24 }}>
                            <div
                                style={{
                                    fontSize: 16,
                                    fontWeight: 500,
                                    color: '#1f2937',
                                    marginBottom: 12,
                                }}
                            >
                                基本情况
                            </div>

                            {/* <Form.Item
                        name="enterpriseName"
                        label="企业名称"
                        rules={[{ required: true, message: '请输入企业名称' }]}
                        style={{ marginBottom: 20 }}
                      >
                        <Input style={COMMON_FIELD_STYLE} />
                      </Form.Item> */}
                            <Form.Item label="数字化水平等级(改造前)" style={{ marginBottom: 20 }}>

                                <Space.Compact style={{ width: '100%' }}>
                                    <Form.Item
                                        name="digitalLevel"
                                        noStyle
                                        rules={[{ required: true, message: '请选择数字化水平等级' }]}

                                    >
                                        <Select
                                            className={modalProps.title == "项目备案审核" ? 'custom-readonly-select' : ''}
                                            style={{ ...COMMON_FIELD_STYLE, flex: 1 }}
                                            // 添加表单绑定属性
                                            disabled={modalProps.title == "项目备案审核"}
                                            value={form.getFieldValue('digitalLevel')}
                                            onChange={(value) => form.setFieldValue('digitalLevel', value)}
                                        >
                                            <Select.Option value="level1">一级</Select.Option>
                                            <Select.Option value="level2">二级</Select.Option>
                                            <Select.Option value="level3">三级</Select.Option>
                                            <Select.Option value="level4">四级</Select.Option>
                                        </Select>
                                    </Form.Item>

                                    <Button
                                        style={{ ...COMMON_FIELD_STYLE, width: 'auto' }}
                                        type="primary"
                                        onClick={() =>
                                            window.open(
                                                'https://ucenter.miit.gov.cn/login.jsp?toUrl=http%3A%2F%2Fzjtx.miit.gov.cn%2Fqyxx%2Fgotoszhsp',
                                            )
                                        }
                                    >
                                        去测试
                                    </Button>
                                </Space.Compact>
                            </Form.Item>
                            <Form.Item
                                name="transformationInvestment"
                                label="改造总花费(万元)"
                                rules={[{ required: true, message: '请输入改造总花费', pattern: /^\d+(\.\d+)?$/ }]}
                                style={{ marginBottom: 20 }}
                            >
                                <Input
                                    className={modalProps.title == "项目备案审核" ? 'custom-readonly-input' : ''}
                                    disabled={modalProps.title == "项目备案审核"} style={COMMON_FIELD_STYLE} />
                            </Form.Item>
                        </div>

                        <div style={{ marginBottom: 24 }}>
                            <div style={{ borderBottom: '1px solid #e8e8e8', marginBottom: 20 }}></div>

                            <div
                                style={{
                                    fontSize: 16,
                                    fontWeight: 500,
                                    color: '#1f2937',
                                    marginBottom: 12,
                                }}
                            >
                                新增/修改数字化改造内容
                            </div>
                            <Form.List name="digitalContentList">
                                {(fields, { add, remove }) => (
                                    <>
                                        {fields.map(({ key, name, ...restField }) => (
                                            <div
                                                key={key}
                                                style={{
                                                    marginBottom: 24,
                                                    borderBottom: '1px solid #e8e8e8',
                                                    paddingBottom: 16,
                                                }}
                                            >
                                                <Row justify="space-between" align="middle">
                                                    <Col>
                                                        <div
                                                            style={{
                                                                fontSize: 16,
                                                                fontWeight: 500,
                                                                color: '#1f2937',
                                                                marginBottom: 12,
                                                                marginLeft: 12,
                                                            }}
                                                        >
                                                            内容 {name + 1}
                                                        </div>
                                                    </Col>
                                                    <Col>
                                                        {
                                                            modalProps.title != "项目备案审核" && (
                                                                <Popconfirm title="是否删除" onConfirm={() => remove(name)}>
                                                                    <Button type="link" danger >
                                                                        删除
                                                                    </Button>
                                                                </Popconfirm>
                                                            )
                                                        }


                                                    </Col>
                                                </Row>
                                                <Form.Item
                                                    {...restField}
                                                    label="产品以及解决方案名称"
                                                    name={[name, 'productName']}
                                                    rules={[{ required: true, message: '请选择产品以及解决方案名称' }]}
                                                    style={{ marginBottom: 20 }}
                                                >

                                                    <Select
                                                        className={modalProps.title == "项目备案审核" ? 'custom-readonly-select' : ''}
                                                        disabled={modalProps.title == "项目备案审核"}
                                                        onChange={(value) => {
                                                            form.setFieldValue(
                                                                ["digitalContentList", name, 'connectService'],
                                                                [...(form.getFieldValue(["digitalContentList", name, 'connectService']) ?? []), connectService.current[value[0]].supplierName])
                                                            form.setFieldValue(
                                                                ["digitalContentList", name, 'craditCode'],
                                                                [...(form.getFieldValue(["digitalContentList", name, 'craditCode']) ?? []), connectService.current[value[0]].xydm])
                                                        }}
                                                        mode="tags" placeholder="请选择产品以及解决方案名称" options={productNameList} />
                                                </Form.Item>
                                                <Form.Item
                                                    {...restField}
                                                    label="关联服务商"
                                                    name={[name, 'connectService']}
                                                    rules={[{ required: true, message: '请选择关联服务商' }]}
                                                    style={{ marginBottom: 20 }}
                                                >
                                                    <Select
                                                        className={modalProps.title == "项目备案审核" ? 'custom-readonly-select' : ''}
                                                        mode='tags' disabled placeholder="请选择关联服务商" options={connectServiceList} />
                                                </Form.Item>
                                                <Form.Item
                                                    {...restField}
                                                    label="关联服务商信用代码"
                                                    name={[name, 'craditCode']}
                                                    rules={[{ required: true, message: '请输入关联服务商信用代码' }]}
                                                    style={{ marginBottom: 20 }}
                                                >
                                                    <Select mode='tags' disabled placeholder="请选择关联服务商信用代码" options={xydmList} />
                                                </Form.Item>
                                                <Form.Item
                                                    {...restField}
                                                    label="数字化内容介绍"
                                                    name={[name, 'digitalContent']}
                                                    rules={[{ required: true, message: '请输入数字化内容介绍' }]}
                                                    style={{ marginBottom: 20 }}
                                                >
                                                    <TextArea
                                                        placeholder="请输入数字化内容介绍"
                                                        allowClear
                                                        showCount
                                                        readOnly={modalProps.title == "项目备案审核"}
                                                        maxLength={500}
                                                        style={{
                                                            minHeight: 120,
                                                            maxHeight: 200,
                                                            resize: 'vertical',
                                                            ...COMMON_FIELD_STYLE,
                                                        }}
                                                    />
                                                </Form.Item>
                                                <Form.Item
                                                    {...restField}
                                                    label="云应用"
                                                    name={[name, 'cloundApp']}
                                                    rules={[{ required: true, message: '请选择云应用' }]}
                                                    style={{ marginBottom: 20 }}
                                                >
                                                    <Select
                                                        className={modalProps.title == "项目备案审核" ? 'custom-readonly-select' : ''}
                                                        disabled={modalProps.title == "项目备案审核"} mode="multiple" style={COMMON_FIELD_STYLE}>
                                                        <Select.Option value="privateCloud">私有云</Select.Option>
                                                        <Select.Option value="publicCloud">公有云</Select.Option>
                                                        <Select.Option value="hybridCloud">混合云</Select.Option>
                                                        <Select.Option value="dedicatedCloud">专有云</Select.Option>
                                                        <Select.Option value="noCloud">未上云</Select.Option>
                                                    </Select>
                                                </Form.Item>
                                                <Form.Item
                                                    {...restField}
                                                    label="云应用情况描述"
                                                    name={[name, 'cloudDesc']}
                                                    // rules={[{ required: true, message: '请输入云应用情况描述' }]}
                                                    style={{ marginBottom: 20 }}
                                                >
                                                    <TextArea
                                                        placeholder="请输入云应用情况描述"
                                                        allowClear
                                                        showCount
                                                        readOnly={modalProps.title == "项目备案审核"}
                                                        maxLength={500}
                                                        style={{
                                                            minHeight: 120,
                                                            maxHeight: 200,
                                                            resize: 'vertical',
                                                            ...COMMON_FIELD_STYLE,
                                                        }}
                                                    />
                                                </Form.Item>
                                                <Form.Item
                                                    {...restField}
                                                    label="改造项目开始时间"
                                                    name={[name, 'programStart']}
                                                    rules={[{ required: true, message: '请选择改造项目开始时间' }]}
                                                    style={{ marginBottom: 20 }}
                                                >
                                                    <DatePicker
                                                        style={{
                                                            ...COMMON_FIELD_STYLE,
                                                            ...(modalProps.title == "项目备案审核" ? {
                                                                background: "#fff",
                                                                color: "rgba(0, 0, 0, 0.85)"
                                                            } : {})
                                                        }}
                                                        disabled={modalProps.title == "项目备案审核"} />
                                                </Form.Item>
                                                <Form.Item
                                                    {...restField}
                                                    label="改造项目结束时间"
                                                    name={[name, 'programEnd']}
                                                    rules={[{ required: true, message: '请选择改造项目结束时间' }]}
                                                    style={{ marginBottom: 20 }}
                                                >
                                                    <DatePicker
                                                        style={{
                                                            ...COMMON_FIELD_STYLE,
                                                            ...(modalProps.title == "项目备案审核" ? {
                                                                background: "#fff",
                                                                color: "rgba(0, 0, 0, 0.85)"
                                                            } : {})
                                                        }}
                                                        disabled={modalProps.title == "项目备案审核"} />
                                                </Form.Item>
                                                <Form.Item
                                                    {...restField}
                                                    label="改造项目单项花费 (万元)"
                                                    name={[name, 'programPay']}
                                                    rules={[{ required: true, message: '请输入改造项目单项花费 (万元)' }]}
                                                    style={{ marginBottom: 20 }}
                                                >
                                                    <Input
                                                        className={modalProps.title == "项目备案审核" ? 'custom-readonly-input' : ''}
                                                        disabled={modalProps.title == "项目备案审核"} placeholder="请输入改造项目单项花费 (万元)" />
                                                </Form.Item>
                                                <Form.Item
                                                    {...restField}
                                                    label="改造合同"
                                                    name={[name, 'changeContract']}
                                                    rules={[{ required: true, message: '请选择改造合同' }]}
                                                    style={{ marginBottom: 20 }}
                                                >
                                                    <Upload
                                                        fileList={hetongList[["digitalContentList", name, 'changeContract'].join("_") as any]}
                                                        beforeUpload={(file) => {
                                                            handleAutoUpload(file, ["digitalContentList", name, 'changeContract']);
                                                            return false;
                                                        }}
                                                        listType="text"
                                                        maxCount={1}
                                                        style={COMMON_FIELD_STYLE}
                                                        onPreview={async (file: any) => {
                                                            // const fileBlob = await filePreview({ path: file.url })
                                                            // console.log(fileBlob)
                                                            try {
                                                                // 阻止默认跳转行为

                                                                // 从file对象中获取文件路径，这里需要根据你的数据结构调整
                                                                const filePath = file.url || file.response?.path || file.path;

                                                                if (!filePath) {
                                                                    message.error('文件路径不存在');
                                                                    return;
                                                                }

                                                                // 调用预览接口获取文件流
                                                                const response = await filePreview(
                                                                    { path: filePath },
                                                                    {
                                                                        responseType: 'blob', // 重要：指定响应类型为 blob
                                                                        getResponse: true, // 获取完整的响应对象
                                                                    }
                                                                );

                                                                // 从响应中获取 blob 数据
                                                                const blob = response.data;

                                                                if (!blob) {
                                                                    message.error('文件获取失败');
                                                                    return;
                                                                }

                                                                // 创建下载链接
                                                                const downloadUrl = window.URL.createObjectURL(blob);
                                                                const link = document.createElement('a');
                                                                link.href = downloadUrl;

                                                                // 设置下载文件名
                                                                const fileName = file.name ||
                                                                    file.response?.name ||
                                                                    'download_' + new Date().getTime();
                                                                link.download = fileName;

                                                                // 触发下载
                                                                document.body.appendChild(link);
                                                                link.click();
                                                                document.body.removeChild(link);

                                                                // 释放URL对象
                                                                window.URL.revokeObjectURL(downloadUrl);

                                                                message.success('文件下载成功');

                                                            } catch (error) {
                                                                console.error('文件下载失败:', error);
                                                                message.error('文件下载失败');
                                                            }
                                                        }}
                                                    >
                                                        <Button
                                                            style={{
                                                                // ...COMMON_FIELD_STYLE,
                                                                ...(modalProps.title == "项目备案审核" ? {
                                                                    background: "#fff",
                                                                    color: "rgba(0, 0, 0, 0.85)"
                                                                } : {})
                                                            }} disabled={modalProps.title == "项目备案审核"} icon={<UploadOutlined />}>点击上传改造合同</Button>
                                                    </Upload>
                                                </Form.Item>
                                                {senceList.map((item, index) => (
                                                    <div
                                                        key={item}
                                                        style={{
                                                            marginBottom: 24,
                                                            borderBottom: '1px solid #e8e8e8',
                                                            paddingBottom: 16,
                                                        }}
                                                    >
                                                        <Row justify="space-between" align="middle">
                                                            <Col>
                                                                <div
                                                                    style={{
                                                                        fontSize: 16,
                                                                        fontWeight: 500,
                                                                        color: '#1f2937',
                                                                        marginBottom: 12,
                                                                    }}
                                                                >
                                                                    场景 {item}
                                                                </div>
                                                            </Col>
                                                            <Col>
                                                                {

                                                                    modalProps.title != "项目备案审核" && (
                                                                        <Popconfirm title="是否删除" onConfirm={() => {
                                                                            setSenceList((prev) => prev.filter((_, idx) => idx !== index));
                                                                        }}>
                                                                            <Button
                                                                                type="link"
                                                                                danger
                                                                            >
                                                                                删除
                                                                            </Button>
                                                                        </Popconfirm>
                                                                    )
                                                                }


                                                            </Col>
                                                        </Row>

                                                        <Form.Item
                                                            {...restField}
                                                            label={`对应的数字化改造需求`}
                                                            name={[name, item, 'scene']}
                                                            rules={[{ required: true, message: `请对应的数字化改造需求` }]}
                                                            style={{ marginBottom: 20 }}
                                                        >
                                                            <TreeSelect
                                                                allowClear
                                                                placeholder="请对应的数字化改造需求"
                                                                style={COMMON_FIELD_STYLE}
                                                                disabled={modalProps.title == "项目备案审核"}
                                                                treeData={condition.map((node) => convertNode(node))}
                                                                treeDefaultExpandAll
                                                                showSearch
                                                                onChange={(value) => {
                                                                    if (value) {
                                                                        const fullPath = fullPathMap[value].join(' / ');
                                                                        form.setFieldValue(['scenes', name, item, 'scene'], fullPath);
                                                                    }
                                                                }}
                                                            />
                                                        </Form.Item>

                                                        <Form.Item
                                                            {...restField}
                                                            label={`场景描述`}
                                                            name={[name, item, 'sceneDesc']}
                                                            rules={[{ required: true, message: `请输入场景描述` }]}
                                                            style={{ marginBottom: 20 }}
                                                        >
                                                            <TextArea
                                                                placeholder={`${item}请输入场景描述`}
                                                                allowClear
                                                                disabled={modalProps.title == "项目备案审核"}
                                                                showCount
                                                                maxLength={500}
                                                                style={{
                                                                    minHeight: 120,
                                                                    maxHeight: 200,
                                                                    resize: 'vertical',
                                                                    ...COMMON_FIELD_STYLE,
                                                                }}
                                                            />
                                                        </Form.Item>
                                                    </div>
                                                ))}
                                            </div>
                                        ))}
                                        {

                                            modalProps.title != "项目备案审核" && (
                                                <Form.Item wrapperCol={{ offset: 5, span: 19 }} style={{ marginTop: 40, textAlign: "center" }}>
                                                    <Button type="primary" onClick={() => add()} >
                                                        +新增数字化改造内容
                                                    </Button>
                                                </Form.Item>
                                            )
                                        }

                                    </>
                                )}
                            </Form.List>
                        </div>

                        <div style={{ marginBottom: 24 }}>
                            <div style={{ borderBottom: '1px solid #e8e8e8', marginBottom: 20 }}></div>

                            <div
                                style={{
                                    fontSize: 16,
                                    fontWeight: 500,
                                    color: '#1f2937',
                                    marginBottom: 12,
                                }}
                            >
                                预期成效
                            </div>

                            <Form.Item
                                name="innovationDimension"
                                label="创新维度"
                                rules={[{ required: true, message: '请输入创新维度' }]}
                                style={{ marginBottom: 20 }}
                            >
                                {/* <Input style={COMMON_FIELD_STYLE} /> */}
                                <TextArea
                                    placeholder={`1.研发经费占营业收入比例（%）
2.关键工序数控化率（%）
3.数字化研发设计工具普及率（%）
4.设备联网率（%）
5.新产品产值率（%）
6.设备数字化率（%）
7.协同研发平台覆盖率（%）
8.新产品研制周期（天）`}
                                    allowClear
                                    showCount
                                    readOnly={modalProps.title == "项目备案审核"}
                                    maxLength={500}
                                    style={{
                                        minHeight: 120,
                                        maxHeight: 200,
                                        resize: 'vertical',
                                        ...COMMON_FIELD_STYLE,
                                    }}
                                />
                            </Form.Item>

                            <Form.Item
                                name="marketDimension"
                                label="市场维度"
                                rules={[{ required: true, message: '请输入市场维度' }]}
                                style={{ marginBottom: 20 }}
                            >
                                {/* <Input style={COMMON_FIELD_STYLE} /> */}
                                <TextArea
                                    placeholder={`1.销售额（万元）
2.主营产品市场占有率（%）
3.线上交易增长率（%）`}
                                    allowClear
                                    showCount
                                    readOnly={modalProps.title == "项目备案审核"}
                                    maxLength={500}
                                    style={{
                                        minHeight: 120,
                                        maxHeight: 200,
                                        resize: 'vertical',
                                        ...COMMON_FIELD_STYLE,
                                    }}
                                />
                            </Form.Item>

                            <Form.Item
                                name="qualityImprovementDimension"
                                label="提质维度"
                                rules={[{ required: true, message: '请输入提质维度' }]}
                                style={{ marginBottom: 20 }}
                            >
                                {/* <Input style={COMMON_FIELD_STYLE} /> */}
                                <TextArea
                                    placeholder={`1.平均核心产品合格率（%）
2.月度平均产品合格率（%）
3.预测性维护准确率（%）
4.智能检测覆盖率（%）
`}
                                    allowClear
                                    showCount
                                    readOnly={modalProps.title == "项目备案审核"}
                                    maxLength={500}
                                    style={{
                                        minHeight: 120,
                                        maxHeight: 200,
                                        resize: 'vertical',
                                        ...COMMON_FIELD_STYLE,
                                    }}
                                />
                            </Form.Item>

                            <Form.Item
                                name="costReductionDimension"
                                label="降本维度"
                                rules={[{ required: true, message: '请输入降本维度' }]}
                                style={{ marginBottom: 20 }}
                            >
                                {/* <Input style={COMMON_FIELD_STYLE} /> */}
                                <TextArea
                                    placeholder={`1.生产成本（万元）
2.管理成本（万元）
3.采购成本（万元）
4.研发成本（万元）
5.能耗成本（万元）
`}
                                    allowClear
                                    showCount
                                    readOnly={modalProps.title == "项目备案审核"}
                                    maxLength={500}
                                    style={{
                                        minHeight: 120,
                                        maxHeight: 200,
                                        resize: 'vertical',
                                        ...COMMON_FIELD_STYLE,
                                    }}
                                />
                            </Form.Item>

                            <Form.Item
                                name="efficiencyIncreaseDimension"
                                label="增效维度"
                                rules={[{ required: true, message: '请输入增效维度' }]}
                                style={{ marginBottom: 20 }}
                            >
                                {/* <Input style={COMMON_FIELD_STYLE} /> */}
                                <TextArea
                                    placeholder={`1.全员劳动生产率（%）
2.销售订单准时交货率（%）
3.采购订单准时交货率（%）
4.生产计划达成率（%）
5.产能利用率（%）
6.库存周转天数（天）
7.库存周转率（%）
8.工单处理时效（h）

`}
                                    allowClear
                                    showCount
                                    readOnly={modalProps.title == "项目备案审核"}
                                    maxLength={500}
                                    style={{
                                        minHeight: 120,
                                        maxHeight: 200,
                                        resize: 'vertical',
                                        ...COMMON_FIELD_STYLE,
                                    }}
                                />
                            </Form.Item>

                            <Form.Item
                                name="greenDimension"
                                label="绿色维度"
                                rules={[{ required: true, message: '请输入绿色维度' }]}
                                style={{ marginBottom: 20 }}
                            >
                                {/* <Input style={COMMON_FIELD_STYLE} /> */}
                                <TextArea
                                    placeholder={`
1.废水排放量（t/d）
2.废气排放量（m³/y）
3.单位产值综合能耗（吨标准煤/万元）
`}
                                    allowClear
                                    readOnly={modalProps.title == "项目备案审核"}
                                    showCount
                                    maxLength={500}
                                    style={{
                                        minHeight: 120,
                                        maxHeight: 200,
                                        resize: 'vertical',
                                        ...COMMON_FIELD_STYLE,
                                    }}
                                />
                            </Form.Item>

                            <Form.Item
                                name="safetyDimension"
                                label="安全维度"
                                rules={[{ required: true, message: '请输入安全维度' }]}
                                style={{ marginBottom: 20 }}
                            >
                                {/* <Input style={COMMON_FIELD_STYLE} /> */}
                                <TextArea
                                    placeholder={`1.事故率（%）
2.安全培训合格率（%）
3.安全漏洞修复时效（h）
`}
                                    allowClear
                                    readOnly={modalProps.title == "项目备案审核"}
                                    showCount
                                    maxLength={500}
                                    style={{
                                        minHeight: 120,
                                        maxHeight: 200,
                                        resize: 'vertical',
                                        ...COMMON_FIELD_STYLE,
                                    }}
                                />
                            </Form.Item>

                            <Form.Item
                                name="otherDimension"
                                label="其他维度"
                                rules={[{ required: true, message: '请输入其他维度' }]}
                                style={{ marginBottom: 20 }}
                            >
                                {/* <Input style={COMMON_FIELD_STYLE} /> */}
                                <TextArea
                                    placeholder="请尽量用若干定量指标描述"
                                    allowClear
                                    showCount
                                    readOnly={modalProps.title == "项目备案审核"}
                                    maxLength={500}
                                    style={{
                                        minHeight: 120,
                                        maxHeight: 200,
                                        resize: 'vertical',
                                        ...COMMON_FIELD_STYLE,
                                    }}
                                />
                            </Form.Item>
                        </div>
                        {/* <Form.Item label={null} style={{ marginTop: 40, textAlign: 'center' }}>

                            <Button
                                type="primary"
                                style={{ marginRight: 10 }}
                            // onClick={submitFun}
                            >
                                暂存
                            </Button>

                            <Button style={{}} type="primary"
                            // onClick={submitFun}
                            >
                                提交
                            </Button>
                        </Form.Item> */}
                        {/* 
                        <div
                            style={{
                                fontSize: 16,
                                fontWeight: 500,
                                color: '#1f2937',
                                marginBottom: 12,
                            }}
                        >
                            项目实施
                        </div>

                        <Form.Item
                            name="isPerformanceEvaluated"
                            label="系统开发"
                            //   rules={[{ required: true, message: '请选择是否已开展绩效评价' }]}
                            style={{ marginBottom: 20 }}
                        >
                            <Checkbox disabled={modalProps.title == "项目备案审核"} />
                        </Form.Item>
                        <Form.Item
                            name="isThrough"
                            label="上线试运行"
                            //   rules={[{ required: true, message: '请选择上线试运行' }]}
                            style={{ marginBottom: 20 }}
                        >
                            <Checkbox disabled={modalProps.title == "项目备案审核"} />
                        </Form.Item>
                        <Form.Item
                            name="isThrough"
                            label="系统验收"
                            //   rules={[{ required: true, message: '请选择上线试运行' }]}
                            style={{ marginBottom: 20 }}
                        >
                            <Checkbox disabled={modalProps.title == "项目备案审核"} />
                        </Form.Item> */}

                        {
                            modalProps.title == "项目备案审核" && (
                                <>
                                    {/* 审核意见（必填） */}
                                    <Divider>审核意见</Divider>
                                    <Form.Item
                                        name="auditRemark"
                                        label={
                                            <span>
                                                审核意见 <span style={{ color: 'red' }}>*</span>
                                            </span>
                                        }
                                        rules={[{ required: true, message: '请填写审核意见' }]}
                                    >
                                        <TextArea
                                            rows={4}
                                            placeholder="请输入审核意见（如：产品信息完整，同意通过；或：缺少技术规格，需退回补充）"
                                        />
                                    </Form.Item>

                                    {/* 审核操作按钮：通过/不通过/退回 */}
                                    <div style={{ display: 'flex', justifyContent: 'flex-end', gap: '16px', marginTop: '16px' }}>
                                        <Button onClick={() => setModalProps(prev => ({ ...prev, visible: false }))}>
                                            取消
                                        </Button>
                                        <Button
                                            danger
                                            icon={<CloseCircleOutlined />}
                                            onClick={() => handleReviewSubmit('rejected')}
                                        >
                                            不通过
                                        </Button>
                                        <Button
                                            icon={<SyncOutlined />}
                                            onClick={() => handleReviewSubmit('returned')}
                                        >
                                            退回
                                        </Button>
                                        <Button
                                            type="primary"
                                            icon={<CheckCircleOutlined />}
                                            onClick={() => handleReviewSubmit('approved')}
                                        >
                                            通过
                                        </Button>
                                    </div>
                                </>
                            )
                        }

                    </div>
                </div>
            </Form>
        </Modal>
    )
}

export default RecordAllInfosPage;